using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Vin.Extension.Framework.Upload.Options;
using Vin.Extension.Framework.Upload.ServiceInterface;
using Vin.Tool.AspNetCore.Extension;
using Vin.Tool.AspNetCore.Service;
using Vin.Tool.Attributes;

namespace Vin.Extension.Framework.Upload.Aliyun.Service;

[Service("aliyun-oss")]
public class AliyunUploadService : VinBaseService, IUploadService
{
    [Inject] private readonly AliyunOssService _aliyunOssService = null!;

    [Inject] private readonly IOptionsMonitor<UploadOption> _uploadOption = null!;

    public async Task<string> UploadFileAsync(IFormFile file, string? baseDir = null)
    {
        return await Task.FromResult(_aliyunOssService.Upload(baseDir ?? _uploadOption.CurrentValue.BaseDir,
            file.FileExtensionName(), file.OpenReadStream()));
    }

    public async Task<string> UploadFileAsync(byte[] file, string extension, string? baseDir = null)
    {
        return await Task.FromResult(_aliyunOssService.Upload(baseDir ?? _uploadOption.CurrentValue.BaseDir, extension,
            file));
    }
}